package com.wan37.logic.handler.server;

import com.wan37.logic.component.LogicWorkerHandlerCenter;
import com.wan37.logic.component.Worker;
import com.wan37.logic.domain.vo.MessageVO;
import com.wan37.logic.global.HandlerManager;
import com.wan37.logic.global.reference.SpringContextHolder;
import com.wan37.logic.handler.LogicServerHandler;
import com.wan37.logic.handler.WorkerHandler;
import com.wan37.logic.handler.message.CGameMoveHandler;
import com.wan37.logic.service.cache.RoleServiceCache;
import com.wan37.logic.service.cache.SceneServiceCache;
import com.wan37.logic.service.cache.UserServiceCache;
import com.wan37.logic.utils.DelayDequeThreadPollUtil;
import com.wan37.logic.utils.RouteUtils;
import com.wan37.protobuf.constant.Common;
import com.wan37.protobuf.constant.CommonBackpack;
import com.wan37.protobuf.constant.PtoNum;
import com.wan37.protobuf.constant.SceneLabel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author : luoyong
 * @date : 2020-07-10 11:27
 **/

public class SuperMoveHandler implements WorkerHandler {
    private static final Logger logger = LoggerFactory.getLogger(CGameMoveHandler.class);

    private SceneServiceCache sceneServiceCache;
    private RouteUtils routeUtils;
    private String currentSceneId;
    private String nextSceneId;
    private String userId;
    private String nextScene;

    public SuperMoveHandler(String currentSceneId, String nextSceneId, String userId, String nextScene) {
        this.currentSceneId = currentSceneId;
        this.nextSceneId = nextSceneId;
        this.userId = userId;
        this.nextScene = nextScene;
        this.sceneServiceCache = SpringContextHolder.getBean("sceneServiceCache");
        this.routeUtils = SpringContextHolder.getBean("routeUtils");
    }

    @Override
    public void execute(Worker worker) throws Exception {
        if (sceneServiceCache.getSceneServiceMap().containsKey(currentSceneId)) {
            if (sceneServiceCache.getSceneServiceMap().get(currentSceneId).getLabel() == SceneLabel.ALWAYS_SCENE) {
                CGameMoveHandler cGameMoveHandler = (CGameMoveHandler) HandlerManager.getMsgHandler
                        (PtoNum.CGAMEMOVE, userId, 0, null, null);
                cGameMoveHandler.move(currentSceneId, nextSceneId, userId, nextScene);
            }
        } else {
            routeUtils.sendItemResponse(CommonBackpack.ITEM_ERROR, "输入的场景不允许进入！", null, new MessageVO(userId));
        }
    }
}
